/**
 * The windows which is launched to chose the mode used in the simmobil session
 * @author jprieur
 * @created April 12 2007
 */
package mygui;

import kernel.Simulator;

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

import utils.*;

public class ModeChooser extends JFrame implements ActionListener
{
    private JButton _new;
    private JButton _load;
    private JButton _quit;

    private JComboBox _combo;

    public ModeChooser()
    {
	setResizable(false);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setLayout(new BorderLayout());
	
	String[] modes = new String[4];
	modes[Simulator.INFRA] = "Infrastructure";
	modes[Simulator.ADHOC] = "Ad hoc";
	modes[Simulator.HYBRID] = "Hybrid";
	modes[Simulator.SENSOR] = "Sensor network";
	_combo = new JComboBox(modes);
	_combo.setSelectedIndex(3);
	add("North", _combo);

	JLabel logo = new JLabel(UIM.createImageIcon("images/logo.png",""));
	add("Center", logo);

	JPanel buttons = new JPanel();
	buttons.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
	_quit = new JButton("Quit");
	_quit.addActionListener(this);
	buttons.add(_quit);
	_load = new JButton("Load");
	_load.addActionListener(this);
	//buttons.add(_load);
	_new = new JButton("Launch");
	_new.addActionListener(this);
	buttons.add(_new);
	add("South", buttons);

	pack();
	WindowUtilities.centerFrame(this);
	setVisible(true);
    }


    public void actionPerformed(ActionEvent e)
    {
	Component source = (Component)e.getSource();
	if(source == _quit)
	    {
		System.exit(0);
	    }
	else if(source == _load)
	    {
		// TODO
	    }
	else if(source == _new)
	    {
		MonIHM gui = new MonIHM(_combo.getSelectedIndex());
		setVisible(false);
		dispose();
	    }
    }    

    public static void main(String args[])
    {
	new ModeChooser();
    }
}
